<template>
    <orh-table pages :pageDate="pageDate" @on-page-change="queryData">
        <Table :columns="columns1" :data="tealeaveList" slot="table" :loading="tableload"  highlight-row ref="currentRowTable"></Table>
    </orh-table>
</template>

<script>
export default {
    components: {
    },
    layout:"menu",
    name: "leave-classinformation",
        data(){
            return {
                pageDate: {
                    total: 0,
                    current_page: 1,
                    per_page: 1
                },
                tealeaveList:[],
                tableload:true,
                columns1: [
                    {
                        title: '学期',
                        render: (h, params) => {
                            return h('div', params.row.semester!=null?params.row.semester.semester_name.zh:'');
                        }
                    },
                    {
                        title: '调课教师',
                        render: (h, params) => {
                            return h('div', params.row.leave_teacher!=null?params.row.leave_teacher.teacher_name.zh:'');
                        }
                    },
                    {
                        title: '请假开始时间',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', params.row.teacher_leave!=null?params.row.teacher_leave.start_time:'');
                        }
                    },
                    {
                        title: '请假结束时间',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', params.row.teacher_leave!=null?params.row.teacher_leave.end_time:'');
                        }
                    },
                    {
                        title: '调课时间',
                        align: 'center',
                        render: (h, params) => {
                            let ss = params.row.date
                            return h('div', ss);
                        }
                    },
                    {
                        title: '调课安排',
                        align: 'center',
                        render: (h, params) => {
                            let ss = `${params.row.course.week.dictionary_name.zh + params.row.course.timeables.name.zh + params.row.course.course.course_name.zh}`
                            return h('div', ss);
                        }
                    },

                ],
            }
        },

        methods: {
            /************************************************************
             * 查看我的调课信息
             ************************************************************/
            queryData(index){
                this.tableload = true
                this.$http.get(`api/leave/v1/teacher_leave/to_me_course?page=${index}`).then(val=>{
                    this.tealeaveList = val.data
                    if(val.pages!=null){
                        this.pageDate.total=val.pages.total
                        this.pageDate.per_page=val.pages.per_page
                        this.pageDate.current_page=val.pages.current_page
                    }
                    this.tableload = false
                }).catch(err => {
                    if (err.code && err.code == 422) {
                        this.$Message.error(err.message);
                    }
                    this.tableload = false
                })
            },
        },
        mounted(){
            this.queryData(this.pageDate.current_page);
        },
}
</script>
